/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.peopleinformation.peopleassessdata.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.peopleinformation.peopleassessdata.entity.PeopleAssessInformation;
import com.jeeplus.modules.peopleinformation.peopleassessdata.mapper.PeopleAssessInformationMapper;

/**
 * 考核人员信息Service
 * @author 刘明星
 * @version 2021-04-19
 */
@Service
@Transactional(readOnly = true)
public class PeopleAssessInformationService extends CrudService<PeopleAssessInformationMapper, PeopleAssessInformation> {

	public PeopleAssessInformation get(String id) {
		return super.get(id);
	}
	
	public List<PeopleAssessInformation> findList(PeopleAssessInformation peopleAssessInformation) {
		return super.findList(peopleAssessInformation);
	}
	
	public Page<PeopleAssessInformation> findPage(Page<PeopleAssessInformation> page, PeopleAssessInformation peopleAssessInformation) {
		String unit = peopleAssessInformation.getUnit();//单位
		String identity = peopleAssessInformation.getIdentity();//岗位类别
		String ticket = peopleAssessInformation.getTicket();//票类别

		if(unit != null && unit.indexOf(",") != -1){
			String[] split = unit.split(",");
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleAssessInformation.setUnitlist(arrayList);
		}else if(unit != null && unit.indexOf(",") == -1){
			String[] split = new String[]{unit};
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleAssessInformation.setUnitlist(arrayList);
		}
		if(identity != null && identity.indexOf(",") != -1){
			String[] split = identity.split(",");
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleAssessInformation.setIdentitylist(arrayList);
		}else if(identity != null && identity.indexOf(",") == -1){
			String[] split = new String[]{identity};
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleAssessInformation.setIdentitylist(arrayList);
		}

		return super.findPage(page, peopleAssessInformation);
	}
	
	@Transactional(readOnly = false)
	public void save(PeopleAssessInformation peopleAssessInformation) {
		super.save(peopleAssessInformation);
			/*
			createData 新增
			deleteData 删除
			status 1 是增加   2 是删除   0 是增加和删除
		 */
		if (peopleAssessInformation.getStatus() != null) {
			switch (peopleAssessInformation.getStatus()) {
				case 0:
					String[] split = peopleAssessInformation.getCreateData().split(",");
					for (String i : split) {
						mapper.creatData(i, peopleAssessInformation);
					}
					String[] split3 = peopleAssessInformation.getDeleteData().split(",");
					for (String i : split3) {
						mapper.deleteData(i, peopleAssessInformation.getUserId());
					}
					break;
				case 1:
					String[] split1 = peopleAssessInformation.getCreateData().split(",");
					for (String i : split1) {
						mapper.creatData(i, peopleAssessInformation);
					}
					break;
				case 2:
					String[] split2 = peopleAssessInformation.getDeleteData().split(",");
					for (int i = 0; i < split2.length; i++) {
						mapper.deleteData(split2[i], peopleAssessInformation.getUserId());
					}
//				for (String i: split2) {
//					mapper.deleteData(i,peopleAssessInformation);
//				}
					break;
				default:
					System.out.println("不进行任何操作");
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(String id, String ticketCount) {
		super.mapper.delete(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteSamelevelTeach(String id, String ticketCount) {
		super.mapper.deleteSamelevelTeach(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteSamelevelOrgan(String id, String ticketCount) {
		super.mapper.deleteSamelevelOrgan(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteServiceTeach(String id, String ticketCount) {
		super.mapper.deleteServiceTeach(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteServiceOrgan(String id, String ticketCount) {
		super.mapper.deleteServiceOrgan(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteCrowdMiddleleader(String id, String ticketCount) {
		super.mapper.deleteCrowdMiddleleader(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteSchoolleaderMiddlecadres(String id, String ticketCount) {
		super.mapper.deleteSchoolleaderMiddlecadres(id, ticketCount);
	}
}